<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改排班管理')"/>
    <style>

        .mainBox {
            width: 90%;
            margin-top: 20px;
            position: absolute;
            top: 0px;
            left: 0px;
            bottom: 50px;
            overflow: auto;
        }

        .bottom {
            width: 100%;
            position: absolute;
            bottom: 0px;
            left: 0px;
            height: 50px;
            line-height: 50px;
            background-color: #F8F8F8;
            border-top: 1px solid #eee;
        }

        .button-container {
            position: absolute;
            right: 15px;
        }
        body{
            background-color: #fff;
        }
    </style>
</head>
<body>
<form class="layui-form" th:object="${sche}">
    <div class="mainBox">
        <div class="main-container">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="layui-form-item">
                <label class="layui-form-label">单位id</label>
                <div class="layui-input-block">
                    <input type="text" name="unitId" th:field="*{unitId}"
                        placeholder="请输入单位id" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">直属机构id</label>
                <div class="layui-input-block">
                    <input type="text" name="deptId" th:field="*{deptId}"
                        placeholder="请输入直属机构id" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">人员id</label>
                <div class="layui-input-block">
                    <input type="text" name="userId" th:field="*{userId}"
                        placeholder="请输入人员id" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工号</label>
                <div class="layui-input-block">
                    <select name="scheType"  >
                        <option value="">所有</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">班制名称</label>
                <div class="layui-input-block">
                    <input type="text" name="scheName" th:field="*{scheName}"
                        placeholder="请输入班制名称" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">班段</label>
                <div class="layui-input-block">
                    <input type="text" name="scheStage" th:field="*{scheStage}"
                        placeholder="请输入班段" class="layui-input" />
                </div>
            </div>
           <div class="layui-form-item">
               <label class="layui-form-label">日期</label>
                   <div class="layui-input-block">
                       <div class="input-group date">
                           <input type="text" name="day" class="layui-input"
                               id="day" >
                       </div>
                   </div>
           </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit=""
                    lay-filter="sche-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
</body>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    layui.use(['form', 'jquery', 'laydate', 'dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        let prefix = pName + "/kq/sche/";

                        laydate.render({
                            elem: '#day'
                        });

        form.on('submit(sche-update)', function (data) {

            let loading = layer.load();
            for (var key in data.field) {
                var type = $(data.form).find("input[name='" + key + "']").attr("type");
                if (type == "checkbox") {
                    var value = "";
                    $(data.form).find("input[name='" + key + "']:checked").each(function () {
                        value += $(this).val() + ",";
                    })
                    if (value != "") {
                        value = value.substr(0, value.length - 1);
                        data.field[key] = value;
                    }

                }
            }
            $.ajax({
                url: prefix + 'update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    layer.close(loading);
                    if (result.code == 1) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.layui.table.reload("sche-table");
                        });
                    } else {
                            layer.alert(result.msg, {icon: 2});
                        }
                }
            })
            return false;
        });
    });
</script>
</html>